﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using CrystalDecisions.CrystalReports.Engine;
using System.Collections.Specialized;

namespace sales.forms
{
    public partial class voucherCashReceive : voucherCashBase
    {
        public voucherCashReceive()
        {
            try
            {
                InitializeComponent();
                this.myCurrency = CommonTypes.Settings.sysMainCurrency;
                dbcrType = debitCredit.credit;

                this.myDetailGrid.myOnCellValueChanged += new common.controls.baseDataGridView.OnCellEvent(gridValueChanged);
                this.myDetailGrid.CellContentClick += new DataGridViewCellEventHandler(gridCellContentClick);

                int mask = common.SysLibs.TurnBitOn(0, CommonTypes.Consts.constFlagPos_VoucherDetailCatCode_RECEIVE);
                (myDetailGrid as sales.Controls.gridVoucherDetail).LoadCatCode1(mask);
            }
            catch (Exception er)
            {
                ShowError(er);
            }
        }

        private myReports.sales.printCashVoucher1 _myCashVoucherReport1 = null;
        private myReports.sales.printCashVoucher1 myCashVoucherReport1
        {
            get
            {
                if (_myCashVoucherReport1 == null) _myCashVoucherReport1 = new myReports.sales.printCashVoucher1();
                return _myCashVoucherReport1;
            }
        }

        private myReports.sales.printCashVoucher3 _myCashVoucherReport3 = null;
        private myReports.sales.printCashVoucher3 myCashVoucherReport3
        {
            get
            {
                if (_myCashVoucherReport3 == null) _myCashVoucherReport3 = new myReports.sales.printCashVoucher3();
                return _myCashVoucherReport3;
            }
        }

        private myReports.sales.printTempCashVoucherWithPay _myTemCashVoucherWithPayReport = null;
        private myReports.sales.printTempCashVoucherWithPay myTemCashVoucherWithPayReport
        {
            get
            {
                if (_myTemCashVoucherWithPayReport == null) _myTemCashVoucherWithPayReport = new myReports.sales.printTempCashVoucherWithPay();
                return _myTemCashVoucherWithPayReport;
            }
        }

        private void PrintCashVoucher(bool fPreviewBeforePrint)
        {
            bool useForeignCurrency = (this.myCurrency != CommonTypes.Settings.sysMainCurrency);
            //Report parametters
            decimal total = (useForeignCurrency ? fSubTotalEd.Value : subTotalEd.Value);
            string custCode = "";
            string[] reportTitle = application.ReportLibs.CompanyHeader(cbCompany.myValue);
            string[] workerName = new string[] { CommonTypes.Settings.sysLoginInfo.FullName, note2Ed.Text.Trim() };

            string currencyDesc = (currencyCb.SelectedValue!=null && currencyCb.SelectedValue.ToString() == CommonTypes.Settings.sysMainCurrency ? CommonTypes.Settings.sysMainCurrencyUnit : currencyCb.Text);
            string[] reportData = new string[]{ cbCompany.Text,editKeyEd.Text.Trim(),this.TitleLbl.Text,"",
                                                common.SysLibs.SayNumber(total,",",currencyDesc),
                                                application.ReportLibs.SayDate(this.dateEd.myDateTime),note1Ed.Text.Trim() 
                                            };
            
            data.masterDS.voucherDetailCatCodeRow voucherDetailCatCodeRow;
            myReports.sales.reportDataSet.cashDetailTblRow rowDetail;
            myReports.sales.reportDataSet.cashDetailTblDataTable myReportTbl = new myReports.sales.reportDataSet.cashDetailTblDataTable();
            myReportTbl.Clear();
            data.masterDS.CustomerRow custRow;
            for (int idx = 0; idx < myApplicationDS.VoucherDetail.Count; idx++)
            {
                rowDetail = myReportTbl.NewcashDetailTblRow();
                if (!myApplicationDS.VoucherDetail[idx].IsrefVoucherNo1Null())
                    rowDetail.voucherNo = myApplicationDS.VoucherDetail[idx].refVoucherNo1;
                if (!myApplicationDS.VoucherDetail[idx].IsrefVoucherDate1Null())
                    rowDetail.ondate = myApplicationDS.VoucherDetail[idx].refVoucherDate1;
                if (myApplicationDS.VoucherDetail[idx].IssaleCodeNull()==false)
                    rowDetail.saleCode = myApplicationDS.VoucherDetail[idx].saleCode;
                else
                    rowDetail.saleCode = "";
                if (!myApplicationDS.VoucherDetail[idx].IscustCodeNull())
                    rowDetail.custCode = myApplicationDS.VoucherDetail[idx].custCode;

                if (useForeignCurrency)
                    rowDetail.amount1 = myApplicationDS.VoucherDetail[idx].fAmount;
                else rowDetail.amount1 = myApplicationDS.VoucherDetail[idx].amount;
                rowDetail.amount2 = 0;

                //Notes
                rowDetail.notes = "";
                if (!myApplicationDS.VoucherDetail[idx].IsnotesNull() && myApplicationDS.VoucherDetail[idx].notes.Trim() != "")
                    rowDetail.notes += (rowDetail.notes == "" ? "" : "-") + myApplicationDS.VoucherDetail[idx].notes;
                else
                {
                    if (!myApplicationDS.VoucherDetail[idx].IscatCode1Null())
                    {
                        voucherDetailCatCodeRow = DataAccess.DataCache.FindVoucherDetailCat(myApplicationDS.VoucherDetail[idx].catCode1);
                        if (voucherDetailCatCodeRow != null)
                            rowDetail.notes += (rowDetail.notes == "" ? "" : "-") + voucherDetailCatCodeRow.description;
                    }
                }
                //Customer name
                custCode = rowDetail.custCode.Trim();
                custRow = DataAccess.DataCache.FindCUSTOMER(custCode);
                if (custRow != null) rowDetail.custName = custRow.name1;
                myReportTbl.AddcashDetailTblRow(rowDetail);
            }
            byte decimalPlace = (useForeignCurrency ? common.SysLibs.GetPrecisionFromMask(CommonTypes.Settings.sysMaskForeignAmt) : common.SysLibs.GetPrecisionFromMask(CommonTypes.Settings.sysMaskLocalAmt));
            string[] fldList = new string[] { "amount1", "sumOfAmount1", "SumOfCashAmount" };
            application.ReportLibs.SetReportDecimalPlace(myCashVoucherReport1, fldList, decimalPlace);

            myCashVoucherReport1.SetDataSource(myReportTbl.DefaultView);
            this.SetReport(myCashVoucherReport1);
            this.SetReport(workerName, "workerName");
            this.SetReport(reportTitle, "reportTitle");
            this.SetReport(reportData, "reportData");
            this.SetReport(application.ReportLibs.GetCompanyLogoFile(cbCompany.myValue), "logoPath");
            this.ShowReport();
        }
        private void PrintCashMemo(bool fPreviewBeforePrint)
        {
            //Report parametters
            double total = 0; double.TryParse(subTotalEd.Text, out total);
            DateTime onDate = DateTime.Today; DateTime.TryParse(this.dateEd.Text, out onDate);
            string[] reportTitle = application.ReportLibs.CompanyHeader(cbCompany.myValue);
            string[] workerName = new string[] { CommonTypes.Settings.sysLoginInfo.FullName,
                                                 note2Ed.Text.Trim()};
            string[] reportData = new string[]{ "BIÊN BẢN GIAO TIỀN",
                                                editKeyEd.Text.Trim(),
                                                this.note1Ed.Text,                              
                                                common.SysLibs.SayNumber((long)total,",","đồng"),
                                                application.ReportLibs.SayDate(onDate)
                                            };
            string custCode = "";
            myReports.sales.reportDataSet.cashDetailTblRow rowDetail;
            myReports.sales.reportDataSet.cashDetailTblDataTable myReportTbl = new myReports.sales.reportDataSet.cashDetailTblDataTable();
            myReportTbl.Clear();

            DataRowView drDetail;
            string saleCode, notes, comment1, voucherDetailCatCode;
            decimal amt1, amt3;
            data.masterDS.voucherDetailCatCodeRow voucherDetailCatCodeRow;
            data.masterDS.CustomerRow custRow;
            data.salesDS.SaleCodeRow saleCodeRow;
            for (int idx = 0; idx < VoucherDetailSource.Count; idx++)
            {
                drDetail = (DataRowView)VoucherDetailSource[idx];
                if (drDetail[myApplicationDS.VoucherDetail.saleCodeColumn.ColumnName].ToString().Trim() == "") continue;
                saleCode = drDetail[myApplicationDS.VoucherDetail.saleCodeColumn.ColumnName].ToString().Trim();
                custCode = drDetail[myApplicationDS.VoucherDetail.custCodeColumn.ColumnName].ToString().Trim();

                voucherDetailCatCode = drDetail[myApplicationDS.VoucherDetail.catCode1Column.ColumnName].ToString().Trim();
                voucherDetailCatCodeRow = DataAccess.DataCache.FindVoucherDetailCat(voucherDetailCatCode);
                notes = (voucherDetailCatCodeRow == null ? "" : voucherDetailCatCodeRow.description);

                comment1 = drDetail[myApplicationDS.VoucherDetail.notesColumn.ColumnName].ToString().Trim();

                rowDetail = myReportTbl.NewcashDetailTblRow();
                rowDetail.saleCode = saleCode; rowDetail.custCode = custCode;
                rowDetail.notes = notes;
                rowDetail.comment1 = comment1;
                rowDetail.amount1 = 0; rowDetail.amount2 = 0; rowDetail.amount3 = 0;

                //SaleOrderDate
                saleCodeRow =  DataAccess.DataCache.Find(mySalesDS.SaleCode, saleCode);
                if (saleCodeRow != null && !saleCodeRow.IscontractDateNull())
                    rowDetail.saleCodeDate = saleCodeRow.contractDate;

                //comment1
                rowDetail.comment1 = "";
                if (!myApplicationDS.VoucherDetail[idx].IsnotesNull() && myApplicationDS.VoucherDetail[idx].notes.Trim() != "")
                    rowDetail.comment1 += (rowDetail.comment1 == "" ? "" : "-") + myApplicationDS.VoucherDetail[idx].notes;

                //Customer name
                custRow = DataAccess.DataCache.FindCUSTOMER(custCode);
                if (custRow != null) rowDetail.custName = custRow.name1;
                myReportTbl.AddcashDetailTblRow(rowDetail);

                amt1 = 0; amt3 = 0;

                decimal.TryParse(drDetail[myApplicationDS.VoucherDetail.amountColumn.ColumnName].ToString(), out amt3);
                rowDetail.amount3 += amt3;
                if (voucherDetailCatCode == CommonTypes.Consts.constVoucherDetailCatCodeMORTAGE)
                {
                    AppLibs.GetBorrowAmount(onDate,new StringCollection{CommonTypes.SaleConsts.constVoucherTypeBorrow}, saleCode, out amt1);
                    rowDetail.amount1 += amt1;
                }
                else
                {
                    rowDetail.amount1 +=  AppLibs.GetTotalSaleAmt(onDate, saleCode);
                }
            }
            myCashVoucherReport3.SetDataSource(myReportTbl.DefaultView);

            bool useForeignCurrency = (this.myCurrency != CommonTypes.Settings.sysMainCurrency);
            byte decimalPlace = (useForeignCurrency ? common.SysLibs.GetPrecisionFromMask(CommonTypes.Settings.sysMaskForeignAmt) : common.SysLibs.GetPrecisionFromMask(CommonTypes.Settings.sysMaskLocalAmt));
            string[] fldList = new string[] { "amount1", "amount2", "amount3", "diffAmt", "sumOfAmount1", "sumOfAmount2", "sumOfAmount1", "sumOfdiffAmt" };
            application.ReportLibs.SetReportDecimalPlace(myCashVoucherReport3, fldList, decimalPlace);

            this.SetReport(myCashVoucherReport3);
            this.SetReport(workerName, "workerName");
            this.SetReport(reportTitle, "reportTitle");
            this.SetReport(reportData, "reportData");
            this.SetReport(application.ReportLibs.GetCompanyLogoFile(cbCompany.myValue), "logoPath");
            this.ShowReport();
        }
        public string myRefVoucher2Type = "";

        private void UpdateTempVoucherNo(bool force)
        {
            for (int idx = 0; idx < myDetailGrid.Rows.Count; idx++)
            {
                UpdateTempVoucherNo(idx, force);
            }
        }
        private void UpdateTempVoucherNo(int rowIdx, bool force)
        {
            if (rowIdx >= myDetailGrid.Rows.Count) return;
            myDetailGrid.Rows[rowIdx].ErrorText = "";
            if (myDetailGrid.Rows[rowIdx].Cells[sales.Controls.gridVoucherDetail.ColumnNames.saleCode.ToString()].Value==null) return;
            string saleCode = myDetailGrid.Rows[rowIdx].Cells[sales.Controls.gridVoucherDetail.ColumnNames.saleCode.ToString()].Value.ToString().Trim();
            if (saleCode == "") return;

            string tmpVoucherNo = myDetailGrid.Rows[rowIdx].Cells[sales.Controls.gridVoucherDetail.ColumnNames.refVoucherNo2.ToString()].Value.ToString().Trim();
            if (force==false && common.StringLibs.IsNullOrEmpty(tmpVoucherNo)==false) return;
            data.applicationDS.VoucherDataTable voucherTbl = DataAccess.DataLibs.GetVoucherBySaleCode(this.myRefVoucher2Type, saleCode);
            if (voucherTbl.Count > 0)
            {
                myDetailGrid.Rows[rowIdx].Cells[sales.Controls.gridVoucherDetail.ColumnNames.refVoucherNo2.ToString()].Value = voucherTbl[0].voucherNo;
            }
            else myDetailGrid.Rows[rowIdx].ErrorText = "Chưa có phiếu thu tạm";
        }

        private void PrintCurrentCashVoucher(bool fPreviewBeforePrint)
        {
            if (myDetailGrid.CurrentRow == null) return;
            data.applicationDS.VoucherDetailRow detailRow = (data.applicationDS.VoucherDetailRow)((DataRowView)myDetailGrid.CurrentRow.DataBoundItem).Row;
            if (detailRow.IsrefVoucherNo2Null() || detailRow.refVoucherNo2.Trim() == "")
            {
                common.SysLibs.ShowErrorMessage("Chưa nhập phiếu thu tạm.");
                return;
            }
            string paidVoucherNo = " ";
            DateTime paidVoucherDate = common.Consts.constNullDate;
            if (!detailRow.IsrefVoucherNo1Null()) paidVoucherNo = detailRow.refVoucherNo1;
            if (!detailRow.IsrefVoucherDate1Null()) paidVoucherDate = detailRow.refVoucherDate1;

            data.applicationDS.VoucherRow voucherRow = DataAccess.DataLibs.GetVoucher(this.myRefVoucher2Type, detailRow.refVoucherNo2);
            if (voucherRow == null)
            {
                common.SysLibs.ShowErrorMessage("Không có phiếu thu tạm số :" + detailRow.refVoucherNo2);
                return;
            }
            decimal saleAmt = (decimal)voucherRow.subTotal1, paidAmt = detailRow.amount;
            string saleCode = (detailRow.IssaleCodeNull() ? "" : detailRow.saleCode);
            string custCode = (detailRow.IscustCodeNull() ? "" : detailRow.custCode);
            data.masterDS.CustomerRow custRow = (custCode == "" ? null : DataAccess.DataCache.FindCUSTOMER(custCode));
            string custName = "", custPhone = "", custAddr = "";
            if (custRow != null)
            {
                custCode = custRow.custCode; custName = custRow.name1; custAddr = custRow.address1;
                custPhone = (custRow.IsphoneNull() ? "" : custRow.phone);
            }

            bool useForeignCurrency = (this.myCurrency != CommonTypes.Settings.sysMainCurrency);
            string amtMask = (useForeignCurrency ? CommonTypes.Settings.sysMaskForeignAmt : CommonTypes.Settings.sysMaskLocalAmt);
            string currencyUnit = (useForeignCurrency ? CommonTypes.Settings.sysMainCurrencyUnit : currencyCb.Text);
            string tmp = application.ReportLibs.SayDate(paidVoucherDate);
            string[] reportData = new string[]{"PHIẾU THU",editKeyEd.Text,custCode,saleCode, 
                                               tmp,"Khách hàng    :", custName,custAddr, custPhone,note1Ed.Text.Trim(),
                                               saleAmt.ToString(amtMask) + " " + currencyUnit,
                                               paidAmt.ToString(amtMask) + " " + currencyUnit,
                                               common.SysLibs.SayNumber((long)paidAmt,"," ,currencyUnit),paidVoucherNo,
                                               note2Ed.Text.Trim(),CommonTypes.Settings.sysCompanyCashier
                                              };
            string[] workerName = new string[]{ CommonTypes.Settings.sysLoginInfo.FullName
                                              };
            string[] reportTitle = application.ReportLibs.CompanyHeader(cbCompany.myValue);

            myReports.sales.reportDataSet.dummyTblDataTable myReportTbl = new myReports.sales.reportDataSet.dummyTblDataTable();
            myReports.sales.reportDataSet.dummyTblRow myReportRow;

            int numberOfCopy = 1;
            if (this.Print2PageMenuItem.Checked) numberOfCopy = 2;
            for (int idx = 0; idx < numberOfCopy; idx++)
            {
                myReportRow = myReportTbl.NewdummyTblRow();
                myReportRow.Column1 = "";
                myReportTbl.AdddummyTblRow(myReportRow);
            }
            myTemCashVoucherWithPayReport.SetDataSource((DataTable)myReportTbl);

            
            byte decimalPlace = (useForeignCurrency ? common.SysLibs.GetPrecisionFromMask(CommonTypes.Settings.sysMaskForeignAmt) : common.SysLibs.GetPrecisionFromMask(CommonTypes.Settings.sysMaskLocalAmt));
            string[] fldList = new string[] { "amount1", "amount2", "amount3", "diffAmt", "sumOfAmount1", "sumOfAmount2", "sumOfAmount1", "sumOfdiffAmt" };
            application.ReportLibs.SetReportDecimalPlace(myTemCashVoucherWithPayReport, fldList, decimalPlace);


            this.SetReport(myTemCashVoucherWithPayReport);
            this.SetReport(reportData, "reportData");
            this.SetReport(reportTitle, "reportTitle");
            this.SetReport(workerName, "workerName");
            this.SetReport(application.ReportLibs.GetCompanyLogoFile(cbCompany.myValue), "logoPath");
            this.ShowReport();
        }
        private void CheckBalanceAmt()
        {
            progressBar.Visible = true; progressBar.Maximum = myDetailGrid.Rows.Count; progressBar.Value = 0;
            DateTime toDate = dateEd.myDateTime;
            decimal totalSaleAmt;
            data.applicationDS.VoucherDetailRow row;
            for (int idx = 0; idx < myDetailGrid.Rows.Count; idx++)
            {
                progressBar.Value++;
                myDetailGrid.Rows[idx].ErrorText = "";
                myDetailGrid.Rows[idx].DefaultCellStyle.BackColor = CommonTypes.Settings.sysColorAmountNoBG;

                if (myDetailGrid.Rows[idx].DataBoundItem == null) continue;
                row = (data.applicationDS.VoucherDetailRow)((DataRowView)myDetailGrid.Rows[idx].DataBoundItem).Row;
                if (row.IssaleCodeNull() || (row.saleCode.Trim() == "") )
                {
                    myDetailGrid.Rows[idx].ErrorText = "Mã bán hàng trồng";
                    continue;
                }
                totalSaleAmt = AppLibs.GetTotalSaleAmt(toDate, row.saleCode);

                if (!row.IscatCode1Null() && row.catCode1 == CommonTypes.Consts.constVoucherDetailCatCodeSALES)
                {
                    if (totalSaleAmt > row.amount)
                    {
                        myDetailGrid.Rows[idx].DefaultCellStyle.BackColor = CommonTypes.Settings.sysColorAmountLoBG;
                        myDetailGrid.Rows[idx].ErrorText = "Số tiền bán lớn hơn số tiền thu";
                    }
                    if (totalSaleAmt < row.amount)
                    {
                        myDetailGrid.Rows[idx].DefaultCellStyle.BackColor = CommonTypes.Settings.sysColorAmountHiBG;
                        myDetailGrid.Rows[idx].ErrorText = "Số tiền bán nhỏ hơn số tiền thu";
                    }
                }
            }
            progressBar.Visible = false;
        }

        #region override function
        protected override bool SaveDetailData(string editKeyId)
        {
            if (!base.SaveDetailData(editKeyId)) return false;
            CheckBalanceAmt();
            return true;
        }
        protected override void SetDetailGrid()
        {
            base.SetDetailGrid();
            string[] colList = new string[] {sales.Controls.gridVoucherDetail.ColumnNames.saleCode.ToString(), 
                                             sales.Controls.gridVoucherDetail.ColumnNames.custCode.ToString(), 
                                             sales.Controls.gridVoucherDetail.ColumnNames.fAmount.ToString(),
                                             sales.Controls.gridVoucherDetail.ColumnNames.amount.ToString(),
                                             sales.Controls.gridVoucherDetail.ColumnNames.refVoucherNo2.ToString(),
                                             sales.Controls.gridVoucherDetail.ColumnNames.catCode1.ToString(),
                                             sales.Controls.gridVoucherDetail.ColumnNames.notes.ToString(),
                                             sales.Controls.gridVoucherDetail.ColumnNames.printBtn.ToString()
                                              };
            this.myDetailGrid.SetColumnVisible(colList);
            this.myDetailGrid.ReOrderColumn(colList);
            this.myDetailGrid.Columns[sales.Controls.gridVoucherDetail.ColumnNames.refVoucherNo2.ToString()].HeaderText = "P.Thu tạm";
        }

        protected override void ModifyMenu()
        {
            ContextMenuStrip contextMenuStrip1 = new ContextMenuStrip();
            ToolStripItem menuItem1;
            menuItem1 = contextMenuStrip1.Items.Add("Bảng kê");
            menuItem1.Click += new System.EventHandler(PrintHandler_Voucher);

            menuItem1 = contextMenuStrip1.Items.Add("Biên bản");
            menuItem1.Click += new System.EventHandler(PrintHandler_Memo);
            printBtn.ContextMenuStrip = contextMenuStrip1;

            ContextMenuStrip contextMenuStrip2 = new ContextMenuStrip();
            ToolStripItem menuItem2;
            menuItem2 = contextMenuStrip2.Items.Add("Số tiền");
            menuItem2.Click += new System.EventHandler(CheckSaleAmt_Handler);

            menuItem2 = contextMenuStrip2.Items.Add("Phiếu thu tạm");
            menuItem2.Click += new System.EventHandler(CheckTmpVoucher_Handler);
            dataCheckBtn.ContextMenuStrip = contextMenuStrip2;
        }

        public override void Print(bool fReview)
        {
            PrintCashVoucher(fReview);
        }
        #endregion

        private void gridCellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                if (myDetailGrid.Columns[e.ColumnIndex].Name == sales.Controls.gridVoucherDetail.ColumnNames.printBtn.ToString())
                    PrintCurrentCashVoucher(printPreviewMenuItem.Checked);
            }
            catch (Exception er)
            {
                this.ShowError(er);
            }
        }
        private void gridValueChanged(object sender, common.controls.GridEventArgs e)
        {
            if (e.ColumnIndex >= this.myDetailGrid.ColumnCount) return;  
            string columName = this.myDetailGrid.Columns[e.ColumnIndex].Name;
            if (columName == sales.Controls.gridVoucherDetail.ColumnNames.saleCode.ToString())
            {
                string code = this.myDetailGrid.CurrentCell.EditedFormattedValue.ToString();
                if (code.Trim() == "") return;
                application.dataFind.mySaleCodeFind.Find(code);
                if (application.dataFind.mySaleCodeFind.selectedDataRow != null)
                {
                    application.dataFind.mySaleCodeFind.Find(this.myDetailGrid.CurrentRow.Cells[columName].Value.ToString());
                    this.myDetailGrid.CurrentRow.Cells[columName].Value = application.dataFind.mySaleCodeFind.selectedDataRow.saleCode;
                    this.myDetailGrid.CurrentRow.Cells[sales.Controls.gridVoucherDetail.ColumnNames.custCode.ToString()].Value = application.dataFind.mySaleCodeFind.selectedDataRow.custCode;
                    UpdateTempVoucherNo(e.RowIndex, false);
                    myDetailSource.ResetCurrentItem();
                }
            }
        }        

        private void dataCheckBtn_Click(object sender, EventArgs e)
        {
            CheckSaleAmt_Handler(sender, e);
        }
        private void CheckSaleAmt_Handler(object sender, EventArgs e)
        {
            try
            {
                this.ShowMessage("");
                CheckBalanceAmt();
            }
            catch (Exception er)
            {
                this.ShowError(er);
            }
        }
        private void CheckTmpVoucher_Handler(object sender, EventArgs e)
        {
            try
            {
                this.ShowMessage("");
                UpdateTempVoucherNo(true);
            }
            catch (Exception er)
            {
                this.ShowError(er);
            }
        }

        private void PrintHandler_Voucher(object sender, EventArgs e)
        {
            try
            {
                PrintCashVoucher(ViewBeforePrintMode);
            }
            catch (Exception er)
            {
                this.ShowError(er);
            }
        }
        private void PrintHandler_Memo(object sender, EventArgs e)
        {
            try
            {
                PrintCashMemo(ViewBeforePrintMode);
            }
            catch (Exception er)
            {
                this.ShowError(er);
            }
        }

    }
}
